{% extends 'base.html' %}

{% block title %}{{ book.title }} - 图书馆管理系统{% endblock %}

{% block content %}
<div class="row">
    <div class="col-md-8">
        <div class="card">
            <div class="card-header">
                <div class="d-flex justify-content-between align-items-center">
                    <h3 class="card-title mb-0">
                        <i class="fas fa-book me-2"></i>{{ book.title }}
                    </h3>
                    <a href="{% url 'books:book_list' %}" class="btn btn-outline-secondary btn-sm">
                        <i class="fas fa-arrow-left me-1"></i>返回列表
                    </a>
                </div>
            </div>
            <div class="card-body">
                <div class="row">
                    <div class="col-md-6">
                        <h5>基本信息</h5>
                        <table class="table table-borderless">
                            <tr>
                                <td><strong>作者：</strong></td>
                                <td>{{ book.author }}</td>
                            </tr>
                            <tr>
                                <td><strong>ISBN：</strong></td>
                                <td>{{ book.isbn }}</td>
                            </tr>
                            <tr>
                                <td><strong>分类：</strong></td>
                                <td>
                                    <span class="badge bg-secondary">{{ book.category.name }}</span>
                                </td>
                            </tr>
                            <tr>
                                <td><strong>出版社：</strong></td>
                                <td>{{ book.publisher|default:"未填写" }}</td>
                            </tr>
                            <tr>
                                <td><strong>出版日期：</strong></td>
                                <td>{{ book.publish_date|date:"Y年m月d日"|default:"未填写" }}</td>
                            </tr>
                            <tr>
                                <td><strong>存放位置：</strong></td>
                                <td>{{ book.location|default:"未填写" }}</td>
                            </tr>
                        </table>
                    </div>
                    <div class="col-md-6">
                        <h5>借阅信息</h5>
                        <table class="table table-borderless">
                            <tr>
                                <td><strong>状态：</strong></td>
                                <td>
                                    <span class="badge status-{{ book.status }}">
                                        {% if book.status == 'available' %}
                                        <i class="fas fa-check me-1"></i>可借阅
                                        {% elif book.status == 'borrowed' %}
                                        <i class="fas fa-times me-1"></i>已借出
                                        {% elif book.status == 'reserved' %}
                                        <i class="fas fa-clock me-1"></i>已预约
                                        {% else %}
                                        <i class="fas fa-tools me-1"></i>维护中
                                        {% endif %}
                                    </span>
                                </td>
                            </tr>
                            <tr>
                                <td><strong>总数量：</strong></td>
                                <td>{{ book.total_copies }} 本</td>
                            </tr>
                            <tr>
                                <td><strong>可借数量：</strong></td>
                                <td>{{ book.available_copies }} 本</td>
                            </tr>
                            <tr>
                                <td><strong>添加时间：</strong></td>
                                <td>{{ book.created_at|date:"Y年m月d日 H:i" }}</td>
                            </tr>
                            <tr>
                                <td><strong>更新时间：</strong></td>
                                <td>{{ book.updated_at|date:"Y年m月d日 H:i" }}</td>
                            </tr>
                        </table>
                    </div>
                </div>

                {% if book.description %}
                <div class="mt-4">
                    <h5>书籍简介</h5>
                    <p class="text-muted">{{ book.description }}</p>
                </div>
                {% endif %}

                <div class="mt-4">
                    <div class="d-flex gap-2">
                        {% if user.is_authenticated %}
                            {% if book.available_copies > 0 %}
                            <a href="{% url 'books:borrow_book' book.id %}" class="btn btn-success">
                                <i class="fas fa-hand-holding me-1"></i>借阅此书
                            </a>
                            {% else %}
                            <a href="{% url 'books:reserve_book' book.id %}" class="btn btn-warning">
                                <i class="fas fa-clock me-1"></i>预约此书
                            </a>
                            {% endif %}
                        {% else %}
                        <a href="{% url 'login' %}" class="btn btn-primary">
                            <i class="fas fa-sign-in-alt me-1"></i>登录后借阅
                        </a>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>

        <!-- 最近借阅记录 -->
        {% if borrow_records %}
        <div class="card mt-4">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="fas fa-history me-2"></i>最近借阅记录
                </h5>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>借阅者</th>
                                <th>借阅日期</th>
                                <th>应还日期</th>
                                <th>状态</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for record in borrow_records %}
                            <tr>
                                <td>{{ record.borrower.username }}</td>
                                <td>{{ record.borrow_date|date:"Y-m-d H:i" }}</td>
                                <td>{{ record.due_date|date:"Y-m-d H:i" }}</td>
                                <td>
                                    {% if record.status == 'borrowed' %}
                                        {% if record.is_overdue %}
                                        <span class="badge bg-danger">逾期</span>
                                        {% else %}
                                        <span class="badge bg-warning">借阅中</span>
                                        {% endif %}
                                    {% elif record.status == 'returned' %}
                                    <span class="badge bg-success">已归还</span>
                                    {% else %}
                                    <span class="badge bg-secondary">{{ record.get_status_display }}</span>
                                    {% endif %}
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
        {% endif %}
    </div>

    <div class="col-md-4">
        <!-- 快速操作 -->
        <div class="card">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="fas fa-tools me-2"></i>快速操作
                </h5>
            </div>
            <div class="card-body">
                <div class="d-grid gap-2">
                    <a href="{% url 'books:book_list' %}" class="btn btn-outline-primary">
                        <i class="fas fa-list me-1"></i>浏览所有书籍
                    </a>
                    <a href="{% url 'books:category_books' book.category.id %}" class="btn btn-outline-info">
                        <i class="fas fa-tags me-1"></i>查看同类书籍
                    </a>
                    {% if user.is_authenticated %}
                    <a href="{% url 'books:my_borrows' %}" class="btn btn-outline-success">
                        <i class="fas fa-list me-1"></i>我的借阅记录
                    </a>
                    {% endif %}
                </div>
            </div>
        </div>

        <!-- 分类信息 -->
        <div class="card mt-3">
            <div class="card-header">
                <h5 class="card-title mb-0">
                    <i class="fas fa-tag me-2"></i>分类信息
                </h5>
            </div>
            <div class="card-body">
                <h6>{{ book.category.name }}</h6>
                {% if book.category.description %}
                <p class="text-muted">{{ book.category.description }}</p>
                {% endif %}
                <small class="text-muted">创建时间：{{ book.category.created_at|date:"Y-m-d" }}</small>
            </div>
        </div>
    </div>
</div>
{% endblock %} 